home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / Chef ƒ 1.1 / Chef code ƒ / chef files.c < prev    next >
Text File  |  1994-02-16  |  4KB  |  157 lines

  1. /**********************************************************************\
  2.  
  3. File:        chef files.c
  4.  
  5. Purpose:    This module handles standard file dialogs for loading
  6.             and saving documents on disk.
  7.  
  8.  
  9. Chef -=- convert text to Swedish chef talk
  10. Copyright ©1994, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "Script.h"
  30. #include "chef files.h"
  31. #include "program globals.h"
  32. #include "msg graphics.h"
  33. #include "msg environment.h"
  34.  
  35. Boolean GetSourceFile(FSSpec *sourceFS, Boolean useOldFile)
  36. {
  37.     Point                where;
  38.     OSErr                isHuman;
  39.     StandardFileReply    reply;
  40.     SFReply                oldReply;
  41.     unsigned int        count;
  42.     SFTypeList            typeList;
  43.     FInfo                fndrInfo;
  44.     long                procID;
  45.     int                    i;
  46.     
  47.     typeList[0]=SAVE_TYPE;
  48.     isHuman=FALSE;
  49.     if ((gStandardFile58) && (!useOldFile))
  50.         StandardGetFile(0L, 1, typeList, &reply);
  51.     else
  52.     {
  53.         where.h = (gMainScreenBounds.right - 348)/2;
  54.         where.v = (gMainScreenBounds.bottom - 200)/3;
  55.         SFGetFile(where, "\p", 0L, 1, typeList, 0L, &oldReply);
  56.         
  57.         reply.sfGood = oldReply.good;
  58.         if (reply.sfGood)
  59.         {
  60.             reply.sfType = oldReply.fType;
  61.             isHuman=GetWDInfo(oldReply.vRefNum, &reply.sfFile.vRefNum,
  62.                                 &reply.sfFile.parID, &procID);
  63.             if (isHuman!=noErr)
  64.             {
  65.                 reply.sfFile.vRefNum = oldReply.vRefNum;
  66.                 reply.sfFile.parID = 0;
  67.             }
  68.             count=oldReply.fName[0];
  69.             for (i=0; i<=count; i++)
  70.                 reply.sfFile.name[i]=oldReply.fName[i];
  71.             
  72.             reply.sfScript=smSystemScript;
  73.             isHuman=HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID,
  74.                                 reply.sfFile.name, &fndrInfo);
  75.             reply.sfFlags=(isHuman==noErr) ? fndrInfo.fdFlags : 0;
  76.             
  77.             reply.sfIsFolder=FALSE;
  78.             reply.sfIsVolume=FALSE;
  79.         }
  80.     }
  81.  
  82.     if ((reply.sfGood) && (!isHuman) && (!useOldFile))
  83.         MyMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name,
  84.                             sourceFS);
  85.         
  86.     return ((reply.sfGood) && (!isHuman));
  87. }
  88.  
  89. Boolean GetDestFile(FSSpec *destFS, Boolean *deleteTheThing)
  90. {
  91.     unsigned int        count;
  92.     Str255                otherName;
  93.     StandardFileReply    reply;
  94.     SFReply                oldReply;
  95.     Point                where;
  96.     FInfo                fndrInfo;
  97.     long                procID;
  98.     OSErr                isHuman;
  99.     int                    i;
  100.         
  101.     if (gStandardFile58)
  102.         StandardPutFile("\pSave converted text as...", destFS->name, &reply);
  103.     else
  104.     {
  105.         where.h = (gMainScreenBounds.right - 304)/2;
  106.         where.v = (gMainScreenBounds.bottom - 184)/3;
  107.         SFPutFile(where, "\pSave converted text as...", destFS->name, 0, &oldReply);
  108.         reply.sfGood = oldReply.good;
  109.         if (reply.sfGood)
  110.         {
  111.             isHuman=GetWDInfo(oldReply.vRefNum, &reply.sfFile.vRefNum,
  112.                                 &reply.sfFile.parID, &procID);
  113.             if (isHuman!=noErr)
  114.             {
  115.                 reply.sfFile.vRefNum = oldReply.vRefNum;
  116.                 reply.sfFile.parID = 0;
  117.             }            
  118.             count=oldReply.fName[0];
  119.             for (i=0; i<=count; i++)
  120.                 reply.sfFile.name[i]=oldReply.fName[i];
  121.             
  122.             reply.sfScript = smSystemScript;
  123.             isHuman=HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID,
  124.                                 reply.sfFile.name, &fndrInfo);
  125.             reply.sfReplacing=(isHuman!=fnfErr);
  126.             
  127.             reply.sfIsFolder=FALSE;
  128.             reply.sfIsVolume=FALSE;
  129.         }
  130.     }
  131.  
  132.     if (reply.sfGood)
  133.     {
  134.         *deleteTheThing=reply.sfReplacing;    
  135.         MyMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name,
  136.                         destFS);
  137.     }
  138.     
  139.     return (reply.sfGood);
  140. }
  141.  
  142. pascal OSErr MyMakeFSSpec(short vRefNum, long parID, ConstStr255Param fileName,
  143.     FSSpecPtr myFSS)
  144. {
  145.     int            i;
  146.     
  147.     if (gHasFSSpecs)
  148.         FSMakeFSSpec(vRefNum, parID, fileName, myFSS);
  149.     else
  150.     {
  151.         myFSS->vRefNum=vRefNum;
  152.         myFSS->parID=parID;
  153.         for (i=fileName[0]; i>=0; i--)
  154.             myFSS->name[i]=fileName[i];
  155.     }
  156. }
  157.